import javafx.scene.Parent;

import javax.annotation.PreDestroy;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Stream;

class  SearchTree{

    class TreeNode{

        public TreeNode leftChild;

        public TreeNode rightChild;


        public int val;

        public TreeNode(int  val){
            this.val = val;
        }
    }

    TreeNode root;   //根节点；


    public void insertTree(int  param){

        if(root==null){
            new TreeNode(param);
            return;
        }
      TreeNode cur = root;
      TreeNode parent = null;   //父节点

        while(cur!=null){

            if(param==cur.val){
                return;
            }else if(cur.val>param){
               parent = cur;
                cur = cur.leftChild;
            }else{
                 parent = cur;
                cur = cur.rightChild;
            }
        }
          TreeNode newNode = new TreeNode(param);

      if(parent.val>param){
          parent.leftChild=newNode;
      }else{
          parent.rightChild=newNode;
      }

    }

    public void createBinaryTree(){

        TreeNode A = new TreeNode(12);
        TreeNode B = new TreeNode(7);
        TreeNode C = new TreeNode(16);
        TreeNode D = new TreeNode(4);
        TreeNode E =new TreeNode(9);
        TreeNode F = new TreeNode(2);
        TreeNode G = new TreeNode(5);
        TreeNode H = new TreeNode(8);
        TreeNode L = new TreeNode(1);
        TreeNode O = new TreeNode(3);
        TreeNode M = new TreeNode(6);
        root = A;
        A.rightChild = C;
        A.leftChild = B;
        B.leftChild= D;
        B.rightChild = E;
        E.leftChild=H;
        D.leftChild=F;
        D.rightChild = G;
        G.rightChild = M;
        F.leftChild = L;
        F.rightChild = O;
    }

    public void bianLi(TreeNode root){

        if(root==null){
            return;
        }

        System.out.println(root.val);
        bianLi(root.leftChild);
        bianLi(root.rightChild);
    }

    public void delTreeNode(int param){

        TreeNode cur = root;
        TreeNode parent = null;
        while(cur!=null){
            if(cur.val>param){
                parent = cur;
                cur = cur.leftChild;
            }
            else if(cur.val<param){
                parent = cur;
                cur = cur.rightChild;
            }else{                             //这里就代表相等了
                if(cur.rightChild==null){
                    if(parent.rightChild==cur){
                        parent.rightChild=cur.leftChild;
                    }else if(parent.leftChild==cur){
                        parent.leftChild=cur.leftChild;
                    }
                    return;
                }else if(cur.leftChild==null) {
                    if (parent.rightChild == cur) {
                        parent.rightChild = cur.rightChild;
                    } else if (parent.leftChild == cur) {
                        parent.leftChild = cur.rightChild;
                    }
                    return;
                }else{                        //这里就代表均不为空了，如果都不为空那就需要找到要删除节点的右子树的最小值（最左节点），然后替换

                   TreeNode tmp = cur.rightChild;
                   parent = cur;

                   while(tmp.leftChild!=null){
                       parent = tmp;
                       tmp = tmp.leftChild;
                   }
                   cur.val = tmp.val;

                   if(parent.leftChild==tmp){
                       parent.leftChild=null;
                   }else if(parent.rightChild==tmp){
                       if(tmp.rightChild!=null){
                           parent.rightChild=tmp.rightChild;
                       }else{
                           parent.rightChild=null;
                       }
                   }
                   return;
                }
            }
        }

    }

}



public class Test1 {
    public static void main(String[] args) {
        List<Integer> list = new ArrayList<>();
        list.add(1);
        list.add(2);
        Stream<Integer> stream = list.stream();
        Map<Integer,Integer> map = new HashMap<>();

        System.out.println(stream);

        BigDecimal bigDecimal = new BigDecimal(1.2);
        System.out.println(bigDecimal);
        int m = 2;
        while(--m>0){
            System.out.println("111");
        }

    }
}
